﻿Module TestConsole
    Sub main()
        ' variable to hold input data to Vash
        Dim input As String = ""

        ' Welcome!
        Console.WriteLine("NVashConsole" & vbCrLf & "2011 Jay Tavares")

        'Get account id from user
        Console.Write("Account id (xxxx-xxxx-xxxx-xxxx): ")
        Dim key As String = Console.ReadLine()

        ' Create an instance of the NVash Generator
        ' You must provide a valid API account id to the constructor
        Dim vash As New NVash.Generator(key)

        ' Explain how to exit
        Console.WriteLine("type 'quit' to exit" & vbCrLf)

        ' Continue generating Vash images until 'quit' is received
        Do Until input = "quit"
            If input <> "" Then
                Try
                    ' Generate the Vash
                    ' GetImage returns a System.Drawing.Image
                    Dim vashResult As Drawing.Image = vash.GetImage(input)

                    ' Create the file name based on the input and format type
                    Dim filename As String = input & "." & System.Enum.GetName(GetType(NVash.ImageFormat), vash.OutputFormat)

                    ' Save the image usine the image.save command
                    ' You could easily pipe the image into a database or winforms ImageBox
                    vashResult.Save(filename)

                    ' Success
                    Console.WriteLine("Vash image saved to {0}", filename)

                Catch ex As Exception
                    ' ERROR, Notify user
                    Console.WriteLine("Error: {0}", ex.Message)
                    End
                End Try
            End If

            ' Query user for input data
            Console.Write("Text to Vash: ")
            input = Console.ReadLine()
        Loop

    End Sub
End Module
